﻿using System;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Sustainalytics.Claims;
using Sustainalytics.ESGRatings.BusinessLogic;
using Sustainalytics.ESGRatings.BusinessLogic.ESGOnlineReport;
using Sustainalytics.Auth.Claims;
using Sustainalytics.Utils;
using System.Web.Http.Cors;

namespace Sustainalytics.ESGRatings.Service.Controllers
{
    [EnableCors(origins: "*", headers: "*", methods: "*")]
    [LogControllerFilter(true, true, false)] 
    [ClaimsChecker("api/v1/company/esg")]
    [RoutePrefix("api/v1/company")]
    public class KeyEsgIssueAssessmentController : ApiController
    {
       // [CacheOutput(ServerTimeSpan = 100, ClientTimeSpan = 0, NoCache = true, MustRevalidate = true, Private = true)]
        [Route("{companyId}/keyEsgIssueAssessment")]
        [UniverseChecker("universeIds", AccountFeature.EsgRatingsOnlineReport)]
        public HttpResponseMessage Get(Guid companyId, [FromUri]int[] universeIds = null)
        {
            try
            {
                IKeyEsgIssuesOnlineReport keyEsgIssuesOnlineReport = new KeyEsgIssuesOnlineReport();

                var data = keyEsgIssuesOnlineReport.GetKeyEsgIssuesByCompanyId(companyId,universeIds);

                return Request.CreateResponse(HttpStatusCode.OK, data);
            }
            catch (ESGReasearchNotFoundException ex)
            {
                return Request.CreateResponse(HttpStatusCode.NotFound, new
                {
                    errCode = ex.GetType().ToString(),
                    message = ex.Message

                });

            }
            catch (ESGReasearchNotInUniversesException ex)
            {
                return Request.CreateResponse(HttpStatusCode.NotFound, new
                {
                    errCode = ex.GetType().ToString(),
                    message = ex.Message

                });
            }
            catch (Exception ex)
            {
                CommonEventSource.Log.Exception(ex);
                return Request.CreateResponse(HttpStatusCode.InternalServerError);
            }
        }

    }
}
